import { getBannerList, getMenuList ,getGoodsList } from '../../api/home'
import router from '@ohos.router'

export default {
    data: {
        bannerList: [], // 轮播图列表
        columns: 5,
        menuList: [], // 菜单列表
        page: 1, // 页码
        pageSize: 10, // 页容量
        goodsList: [] // 商品列表
    },
    async getBannerListData() {
        const res = await getBannerList()
        this.bannerList = res.data
    },
    async getMenuListData() {
        const res = await getMenuList()
        this.menuList = res.data
    },
    async getGoodsListData() {
        const res = await getGoodsList({
            page: this.page,
            pageSize: this.pageSize
        })
        console.log('---getGoodsListData---',res.data)
        this.goodsList = [...this.goodsList,...res.data]
    },
    // 滚动到底部
    onScrollBottom() {
        console.log('---onScrollBottom---')
    },
    // 跳转到详情页面
    goToGoodsDetail(proid) {
        router.pushUrl({
            url: 'pages/goods_detail/goods_detail',
            params: {
                proid
            }
        })
    },
    onInit() {
        this.getBannerListData()
        this.getMenuListData()
        this.getGoodsListData()
    }
}
